<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Sequelize 学习笔记 | 仲灏小栈</title>
    <meta name="generator" content="VuePress 1.8.0">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="专注web全栈学习与总结。JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github等技术文章。">
    <meta name="keywords" content="前端博客,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown">
    <meta name="baidu-site-verification" content="code-5CGlqw1B4p">
    <meta name="google-site-verification" content="PbO8RiLRwDnNwqNFNGnaxZnEFB3CqcGMCGoloYfQXV0">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/assets/css/0.styles.15972595.css" as="style"><link rel="preload" href="/assets/js/app.2005d9cf.js" as="script"><link rel="preload" href="/assets/js/2.26fadcea.js" as="script"><link rel="preload" href="/assets/js/31.c99d1817.js" as="script"><link rel="prefetch" href="/assets/js/10.0a7a4ca4.js"><link rel="prefetch" href="/assets/js/100.3309ce28.js"><link rel="prefetch" href="/assets/js/101.ac045b1a.js"><link rel="prefetch" href="/assets/js/102.e80bc311.js"><link rel="prefetch" href="/assets/js/103.bf660db8.js"><link rel="prefetch" href="/assets/js/104.b26aecd4.js"><link rel="prefetch" href="/assets/js/105.0e9ab80d.js"><link rel="prefetch" href="/assets/js/106.b590426c.js"><link rel="prefetch" href="/assets/js/107.5bf74c11.js"><link rel="prefetch" href="/assets/js/108.ffdc48f3.js"><link rel="prefetch" href="/assets/js/109.8da9360f.js"><link rel="prefetch" href="/assets/js/11.d9ff276d.js"><link rel="prefetch" href="/assets/js/110.3986bd59.js"><link rel="prefetch" href="/assets/js/111.1522ded7.js"><link rel="prefetch" href="/assets/js/12.1fe7afa3.js"><link rel="prefetch" href="/assets/js/13.5e3a6c9a.js"><link rel="prefetch" href="/assets/js/14.541bbe3d.js"><link rel="prefetch" href="/assets/js/15.f7a50163.js"><link rel="prefetch" href="/assets/js/16.2f792024.js"><link rel="prefetch" href="/assets/js/17.a1b6c76e.js"><link rel="prefetch" href="/assets/js/18.44579087.js"><link rel="prefetch" href="/assets/js/19.4ea5fdf4.js"><link rel="prefetch" href="/assets/js/20.e975ae71.js"><link rel="prefetch" href="/assets/js/21.8f6a653b.js"><link rel="prefetch" href="/assets/js/22.f7fe055a.js"><link rel="prefetch" href="/assets/js/23.e404dad6.js"><link rel="prefetch" href="/assets/js/24.fe3bc22e.js"><link rel="prefetch" href="/assets/js/25.85d2cc13.js"><link rel="prefetch" href="/assets/js/26.9f14e07f.js"><link rel="prefetch" href="/assets/js/27.d49bdf6c.js"><link rel="prefetch" href="/assets/js/28.72ba52cd.js"><link rel="prefetch" href="/assets/js/29.2e392833.js"><link rel="prefetch" href="/assets/js/3.7675493a.js"><link rel="prefetch" href="/assets/js/30.b69d63e5.js"><link rel="prefetch" href="/assets/js/32.6d83d1c4.js"><link rel="prefetch" href="/assets/js/33.bebcb9b5.js"><link rel="prefetch" href="/assets/js/34.8f621c93.js"><link rel="prefetch" href="/assets/js/35.6606e0ad.js"><link rel="prefetch" href="/assets/js/36.75614371.js"><link rel="prefetch" href="/assets/js/37.4ce9e497.js"><link rel="prefetch" href="/assets/js/38.95263d32.js"><link rel="prefetch" href="/assets/js/39.a86d2616.js"><link rel="prefetch" href="/assets/js/4.d95386e0.js"><link rel="prefetch" href="/assets/js/40.e7f88f7e.js"><link rel="prefetch" href="/assets/js/41.644d2886.js"><link rel="prefetch" href="/assets/js/42.a9398322.js"><link rel="prefetch" href="/assets/js/43.50ffced2.js"><link rel="prefetch" href="/assets/js/44.8a76f778.js"><link rel="prefetch" href="/assets/js/45.d825d0e7.js"><link rel="prefetch" href="/assets/js/46.e692b0d4.js"><link rel="prefetch" href="/assets/js/47.4a5600e2.js"><link rel="prefetch" href="/assets/js/48.b58a480d.js"><link rel="prefetch" href="/assets/js/49.c31716d2.js"><link rel="prefetch" href="/assets/js/5.77e36999.js"><link rel="prefetch" href="/assets/js/50.5c5f704f.js"><link rel="prefetch" href="/assets/js/51.3b090e9a.js"><link rel="prefetch" href="/assets/js/52.a2846fa7.js"><link rel="prefetch" href="/assets/js/53.08563d97.js"><link rel="prefetch" href="/assets/js/54.abaa1adf.js"><link rel="prefetch" href="/assets/js/55.79ddef5b.js"><link rel="prefetch" href="/assets/js/56.8fc21a8e.js"><link rel="prefetch" href="/assets/js/57.a7a7e91e.js"><link rel="prefetch" href="/assets/js/58.395fd83e.js"><link rel="prefetch" href="/assets/js/59.b2899c75.js"><link rel="prefetch" href="/assets/js/6.ed7c7deb.js"><link rel="prefetch" href="/assets/js/60.12cf70af.js"><link rel="prefetch" href="/assets/js/61.bbb7862b.js"><link rel="prefetch" href="/assets/js/62.ec59ffa8.js"><link rel="prefetch" href="/assets/js/63.f4d6c257.js"><link rel="prefetch" href="/assets/js/64.9e382220.js"><link rel="prefetch" href="/assets/js/65.94ab71cc.js"><link rel="prefetch" href="/assets/js/66.33c7d856.js"><link rel="prefetch" href="/assets/js/67.6d9b7cc8.js"><link rel="prefetch" href="/assets/js/68.63f4486e.js"><link rel="prefetch" href="/assets/js/69.fd717229.js"><link rel="prefetch" href="/assets/js/7.05321aa0.js"><link rel="prefetch" href="/assets/js/70.b37bad49.js"><link rel="prefetch" href="/assets/js/71.bf0f14a3.js"><link rel="prefetch" href="/assets/js/72.37e36450.js"><link rel="prefetch" href="/assets/js/73.d6b8cf7a.js"><link rel="prefetch" href="/assets/js/74.66cae9eb.js"><link rel="prefetch" href="/assets/js/75.f56a19ed.js"><link rel="prefetch" href="/assets/js/76.e9d0a86e.js"><link rel="prefetch" href="/assets/js/77.6f880a29.js"><link rel="prefetch" href="/assets/js/78.bd4f38f3.js"><link rel="prefetch" href="/assets/js/79.f22e09a9.js"><link rel="prefetch" href="/assets/js/8.58ff24c5.js"><link rel="prefetch" href="/assets/js/80.c7a75ffd.js"><link rel="prefetch" href="/assets/js/81.60c66414.js"><link rel="prefetch" href="/assets/js/82.1cac8d03.js"><link rel="prefetch" href="/assets/js/83.dca1d99b.js"><link rel="prefetch" href="/assets/js/84.8c41ec82.js"><link rel="prefetch" href="/assets/js/85.af3896bc.js"><link rel="prefetch" href="/assets/js/86.b30b6900.js"><link rel="prefetch" href="/assets/js/87.b51ef412.js"><link rel="prefetch" href="/assets/js/88.d3803962.js"><link rel="prefetch" href="/assets/js/89.7d9cb78b.js"><link rel="prefetch" href="/assets/js/9.40722af3.js"><link rel="prefetch" href="/assets/js/90.31875659.js"><link rel="prefetch" href="/assets/js/91.6be253a0.js"><link rel="prefetch" href="/assets/js/92.db3fd2c0.js"><link rel="prefetch" href="/assets/js/93.0eae35a1.js"><link rel="prefetch" href="/assets/js/94.3068fcfa.js"><link rel="prefetch" href="/assets/js/95.0aa43f4e.js"><link rel="prefetch" href="/assets/js/96.5dd378f0.js"><link rel="prefetch" href="/assets/js/97.f475d7a5.js"><link rel="prefetch" href="/assets/js/98.c7b425d3.js"><link rel="prefetch" href="/assets/js/99.91630bf2.js">
    <link rel="stylesheet" href="/assets/css/0.styles.15972595.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu have-body-img"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/img/logo.png" alt="仲灏小栈" class="logo"> <span class="site-name can-hide">仲灏小栈</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/web/" class="nav-link">大前端</a></div><div class="nav-item"><a href="/backend-opt/" class="nav-link">后端&amp;运维</a></div><div class="nav-item"><a href="/other-tech/" class="nav-link">其他</a></div><div class="nav-item"><a href="/tech-live/" class="nav-link">生活</a></div><div class="nav-item"><a href="/about/" class="nav-link">关于我</a></div><div class="nav-item"><a href="/favorite/" class="nav-link">收藏</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com/izhaong" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="https://cdn.jsdelivr.net/gh/izhaong/izhaong.com-oss/site-data/avatar/avatar-wx.jpg"> <div class="blogger-info"><h3>仲灏</h3> <span>诚意, 正心, 格物, 致知</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/web/" class="nav-link">大前端</a></div><div class="nav-item"><a href="/backend-opt/" class="nav-link">后端&amp;运维</a></div><div class="nav-item"><a href="/other-tech/" class="nav-link">其他</a></div><div class="nav-item"><a href="/tech-live/" class="nav-link">生活</a></div><div class="nav-item"><a href="/about/" class="nav-link">关于我</a></div><div class="nav-item"><a href="/favorite/" class="nav-link">收藏</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com/izhaong" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>HTML&amp;CSS</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>JavaScript</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Node</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/febcd5/" class="sidebar-link">nvm 使用</a></li><li><a href="/pages/b378af/" class="sidebar-link">nvm 深度使用解析</a></li><li><a href="/pages/96c6f8/" class="sidebar-link">pnpm 学习</a></li><li><a href="/pages/8743eb/" class="sidebar-link">pnpm 使用及问题处理</a></li><li><a href="/pages/037850/" class="sidebar-link">koa学习</a></li><li><a href="/pages/3e0a1c/" class="sidebar-link">restful api笔记</a></li><li><a href="/pages/1210/" class="sidebar-link">Egg.js 技巧</a></li><li><a href="/pages/9da7c4/" aria-current="page" class="active sidebar-link">Sequelize 学习笔记</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/9da7c4/#sequelize-中文文档入门" class="sidebar-link">Sequelize 中文文档入门</a></li><li class="sidebar-sub-header"><a href="/pages/9da7c4/#基本设置" class="sidebar-link">基本设置</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/9da7c4/#表名推断" class="sidebar-link">表名推断</a></li><li class="sidebar-sub-header"><a href="/pages/9da7c4/#模型同步" class="sidebar-link">模型同步</a></li><li class="sidebar-sub-header"><a href="/pages/9da7c4/#时间戳" class="sidebar-link">时间戳</a></li><li class="sidebar-sub-header"><a href="/pages/9da7c4/#获取的值变更-设置值变更-getter-setter" class="sidebar-link">获取的值变更, 设置值变更(getter, setter)</a></li></ul></li><li class="sidebar-sub-header"><a href="/pages/9da7c4/#模型-model" class="sidebar-link">模型 Model</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/9da7c4/#定义模型" class="sidebar-link">定义模型</a></li><li class="sidebar-sub-header"><a href="/pages/9da7c4/#验证和约束" class="sidebar-link">验证和约束</a></li></ul></li><li class="sidebar-sub-header"><a href="/pages/9da7c4/#基本查询" class="sidebar-link">基本查询</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/9da7c4/#排序" class="sidebar-link">排序</a></li></ul></li></ul></li><li><a href="/pages/110928/" class="sidebar-link">npm 使用记录</a></li><li><a href="/pages/50e782/" class="sidebar-link">node 记错修复</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Vue</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>React</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>小程序</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>跨端</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Electron</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>浏览器</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>其他</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-0c557b5e><div class="articleInfo" data-v-0c557b5e><ul class="breadcrumbs" data-v-0c557b5e><li data-v-0c557b5e><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-0c557b5e></a></li> <li data-v-0c557b5e><a href="/web/#大前端" data-v-0c557b5e>大前端</a></li><li data-v-0c557b5e><a href="/web/#Node" data-v-0c557b5e>Node</a></li></ul> <div class="info" data-v-0c557b5e><div title="作者" class="author iconfont icon-touxiang" data-v-0c557b5e><a href="https://github.com/izhaong" target="_blank" title="作者" class="beLink" data-v-0c557b5e>仲灏</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-0c557b5e><a href="javascript:;" data-v-0c557b5e>2021-12-24</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-content"></div></div></div> <h1><img src="">Sequelize 学习笔记<!----></h1> <!----> <div class="theme-vdoing-content content__default"><h2 id="sequelize-中文文档入门"><a href="#sequelize-中文文档入门" class="header-anchor">#</a> <a href="https://www.sequelize.com.cn/" target="_blank" rel="noopener noreferrer"><strong>Sequelize 中文文档</strong>入门 <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2> <h1 id="核心概念"><a href="#核心概念" class="header-anchor">#</a> 核心概念</h1> <h2 id="基本设置"><a href="#基本设置" class="header-anchor">#</a> 基本设置</h2> <h3 id="表名推断"><a href="#表名推断" class="header-anchor">#</a> 表名推断</h3> <p>默认情况下,当未提供表名时,Sequelize 会自动将模型名复数并将其用作表名. 这种复数是通过称为 <a href="https://www.npmjs.com/package/inflection" target="_blank" rel="noopener noreferrer">inflection<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 的库在后台完成的,因此可以正确计算不规则的复数(例如 <code>person -&gt; people</code>).</p> <h4 id="强制表名称等于模型名称"><a href="#强制表名称等于模型名称" class="header-anchor">#</a> 强制表名称等于模型名称</h4> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code>sequelize<span class="token punctuation">.</span><span class="token function">define</span><span class="token punctuation">(</span><span class="token string">'User'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
  <span class="token comment">// ... (属性)</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
  freezeTableName<span class="token operator">:</span> <span class="token boolean">true</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h4 id="直接提供表名"><a href="#直接提供表名" class="header-anchor">#</a> 直接提供表名</h4> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code>sequelize<span class="token punctuation">.</span><span class="token function">define</span><span class="token punctuation">(</span><span class="token string">'User'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
  <span class="token comment">// ... (属性)</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
  tableName<span class="token operator">:</span> <span class="token string">'Employees'</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="模型同步"><a href="#模型同步" class="header-anchor">#</a> 模型同步</h3> <ul><li><p><code>User.sync()</code> - 如果表不存在,则创建该表(如果已经存在,则不执行任何操作)</p></li> <li><p><code>User.sync({ force: true })</code> - 将创建表,如果表已经存在,则将其首先删除</p></li> <li><p><code>User.sync({ alter: true })</code> - 这将检查数据库中表的当前状态(它具有哪些列,它们的数据类型等),然后在表中进行必要的更改以使其与模型匹配</p></li></ul> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">await</span> User<span class="token punctuation">.</span><span class="token function">sync</span><span class="token punctuation">(</span><span class="token punctuation">{</span> force<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&quot;用户模型表刚刚(重新)创建！&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="时间戳"><a href="#时间戳" class="header-anchor">#</a> 时间戳</h3> <p>默认情况下,Sequelize 使用数据类型 <code>DataTypes.DATE</code> 自动向每个模型添加 <code>createdAt</code> 和 <code>updatedAt</code> 字段. 这些字段会自动进行管理 - 每当你使用Sequelize 创建或更新内容时,这些字段都会被自动设置. <code>createdAt</code> 字段将包含代表创建时刻的时间戳,而 <code>updatedAt</code> 字段将包含最新更新的时间戳.</p> <p>对于带有 <code>timestamps: false</code> 参数的模型,可以禁用此行为：</p> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code>sequelize<span class="token punctuation">.</span><span class="token function">define</span><span class="token punctuation">(</span><span class="token string">'User'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
<span class="token comment">// ... (属性)</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
  timestamps<span class="token operator">:</span> <span class="token boolean">false</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>也可以只启用 <code>createdAt</code>/<code>updatedAt</code> 之一,并为这些列提供自定义名称：</p> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">class</span> <span class="token class-name">Foo</span> <span class="token keyword">extends</span> <span class="token class-name">Model</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
Foo<span class="token punctuation">.</span><span class="token function">init</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token comment">/* 属性 */</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
  sequelize<span class="token punctuation">,</span>
<span class="token comment">// 不要忘记启用时间戳！</span>
  timestamps<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
<span class="token comment">// 不想要 createdAt</span>
  createdAt<span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
<span class="token comment">// 想要 updatedAt 但是希望名称叫做 updateTimestamp</span>
  updatedAt<span class="token operator">:</span> <span class="token string">'updateTimestamp'</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h3 id="获取的值变更-设置值变更-getter-setter"><a href="#获取的值变更-设置值变更-getter-setter" class="header-anchor">#</a> 获取的值变更, 设置值变更(getter, setter)</h3> <h4 id="获取的值变更"><a href="#获取的值变更" class="header-anchor">#</a> 获取的值变更</h4> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">const</span> User <span class="token operator">=</span> sequelize<span class="token punctuation">.</span><span class="token function">define</span><span class="token punctuation">(</span><span class="token string">'user'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
  <span class="token comment">// 假设我们想要以大写形式查看每个用户名,</span>
  <span class="token comment">// 即使它们在数据库本身中不一定是大写的</span>
  username<span class="token operator">:</span> <span class="token punctuation">{</span>
    type<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">STRING</span><span class="token punctuation">,</span>
    <span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">const</span> rawValue <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getDataValue</span><span class="token punctuation">(</span>username<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">return</span> rawValue <span class="token operator">?</span> rawValue<span class="token punctuation">.</span><span class="token function">toUpperCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">:</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><h4 id="设置值变更"><a href="#设置值变更" class="header-anchor">#</a> 设置值变更</h4> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">const</span> User <span class="token operator">=</span> sequelize<span class="token punctuation">.</span><span class="token function">define</span><span class="token punctuation">(</span><span class="token string">'user'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
  username<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">STRING</span><span class="token punctuation">,</span>
  password<span class="token operator">:</span> <span class="token punctuation">{</span>
    type<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">STRING</span><span class="token punctuation">,</span>
    <span class="token function">set</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token comment">// 在数据库中以明文形式存储密码是很糟糕的.</span>
      <span class="token comment">// 使用适当的哈希函数来加密哈希值更好.</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setDataValue</span><span class="token punctuation">(</span><span class="token string">'password'</span><span class="token punctuation">,</span> <span class="token function">hash</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><h2 id="模型-model"><a href="#模型-model" class="header-anchor">#</a> 模型 Model</h2> <h3 id="定义模型"><a href="#定义模型" class="header-anchor">#</a> 定义模型</h3> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">class</span> <span class="token class-name">Foo</span> <span class="token keyword">extends</span> <span class="token class-name">Model</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
Foo<span class="token punctuation">.</span><span class="token function">init</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token comment">// 如果未设置，实例化将自动将标志设置为true</span>
  flag<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">BOOLEAN</span><span class="token punctuation">,</span> allowNull<span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> defaultValue<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token comment">// 日期的默认值=&gt;当前时间</span>
  myDate<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">DATE</span><span class="token punctuation">,</span> defaultValue<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">NOW</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token comment">// setting allowNull to false will add NOT NULL to the column, which means an error will be</span>
  <span class="token comment">// thrown from the DB when the query is executed if the column is null. If you want to check that a value</span>
  <span class="token comment">// is not null before querying the DB, look at the validations section below.</span>
  title<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">STRING</span><span class="token punctuation">,</span> allowNull<span class="token operator">:</span> <span class="token boolean">false</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token comment">// Creating two objects with the same value will throw an error. The unique property can be either a</span>
  <span class="token comment">// boolean, or a string. If you provide the same string for multiple columns, they will form a</span>
  <span class="token comment">// composite unique key.</span>
  uniqueOne<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">STRING</span><span class="token punctuation">,</span>  unique<span class="token operator">:</span> <span class="token string">'compositeIndex'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
  uniqueTwo<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">INTEGER</span><span class="token punctuation">,</span> unique<span class="token operator">:</span> <span class="token string">'compositeIndex'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token comment">// The unique property is simply a shorthand to create a unique constraint.</span>
  someUnique<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">STRING</span><span class="token punctuation">,</span> unique<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token comment">// Go on reading for further information about primary keys</span>
  identifier<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">STRING</span><span class="token punctuation">,</span> primaryKey<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token comment">// autoIncrement can be used to create auto_incrementing integer columns</span>
  incrementMe<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">INTEGER</span><span class="token punctuation">,</span> autoIncrement<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token comment">// You can specify a custom column name via the 'field' attribute:</span>
  fieldWithUnderscores<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">STRING</span><span class="token punctuation">,</span> field<span class="token operator">:</span> <span class="token string">'field_with_underscores'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token comment">// It is possible to create foreign keys:</span>
  bar_id<span class="token operator">:</span> <span class="token punctuation">{</span>
    type<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">INTEGER</span><span class="token punctuation">,</span>

    references<span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token comment">// This is a reference to another model</span>
      model<span class="token operator">:</span> Bar<span class="token punctuation">,</span>

      <span class="token comment">// This is the column name of the referenced model</span>
      key<span class="token operator">:</span> <span class="token string">'id'</span><span class="token punctuation">,</span>

      <span class="token comment">// With PostgreSQL, it is optionally possible to declare when to check the foreign key constraint, passing the Deferrable type.</span>
      deferrable<span class="token operator">:</span> Deferrable<span class="token punctuation">.</span><span class="token constant">INITIALLY_IMMEDIATE</span>
      <span class="token comment">// Options:</span>
      <span class="token comment">// - `Deferrable.INITIALLY_IMMEDIATE` - Immediately check the foreign key constraints</span>
      <span class="token comment">// - `Deferrable.INITIALLY_DEFERRED` - Defer all foreign key constraint check to the end of a transaction</span>
      <span class="token comment">// - `Deferrable.NOT` - Don't defer the checks at all (default) - This won't allow you to dynamically change the rule in a transaction</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token comment">// Comments can only be added to columns in MySQL, MariaDB, PostgreSQL and MSSQL</span>
  commentMe<span class="token operator">:</span> <span class="token punctuation">{</span>
    type<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">INTEGER</span><span class="token punctuation">,</span>
    comment<span class="token operator">:</span> <span class="token string">'This is a column name that has a comment'</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
  sequelize<span class="token punctuation">,</span>
  modelName<span class="token operator">:</span> <span class="token string">'foo'</span><span class="token punctuation">,</span>

  <span class="token comment">// Using `unique: true` in an attribute above is exactly the same as creating the index in the model's options:</span>
  indexes<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span> unique<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> fields<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">'someUnique'</span><span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br></div></div><h3 id="验证和约束"><a href="#验证和约束" class="header-anchor">#</a> 验证和约束</h3> <p>使用自定义错误消息代替validator提供的错误消息。使用一个对象，而不是纯值或参数数组，例如验证器不需要参数，可以给自定义消息</p> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code>isInt<span class="token operator">:</span> <span class="token punctuation">{</span>
  msg<span class="token operator">:</span> <span class="token string">&quot;必须是整数&quot;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>你也可以有条件地允许空值，用一个定制的验证器，因为它不会被跳过:</p> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">class</span> <span class="token class-name">User</span> <span class="token keyword">extends</span> <span class="token class-name">Model</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
User<span class="token punctuation">.</span><span class="token function">init</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  age<span class="token operator">:</span> Sequelize<span class="token punctuation">.</span><span class="token constant">INTEGER</span><span class="token punctuation">,</span>
  name<span class="token operator">:</span> <span class="token punctuation">{</span>
    type<span class="token operator">:</span> DataTypes<span class="token punctuation">.</span><span class="token constant">STRING</span><span class="token punctuation">,</span>
    allowNull<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
    validate<span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token function">customValidator</span><span class="token punctuation">(</span><span class="token parameter">value</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>value <span class="token operator">===</span> <span class="token keyword">null</span> <span class="token operator">&amp;&amp;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>age <span class="token operator">!==</span> <span class="token number">10</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
          <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">Error</span><span class="token punctuation">(</span><span class="token string">&quot;name can't be null unless age is 10&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> sequelize <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h2 id="基本查询"><a href="#基本查询" class="header-anchor">#</a> 基本查询</h2> <h3 id="排序"><a href="#排序" class="header-anchor">#</a> 排序</h3> <p>order选项接受一个项目数组来对查询进行排序，或者使用sequelize方法。这些项目本身就是以[列，方向]的形式排列的。该列将被正确转义，方向将在有效方向的白名单中被检查(如ASC、DESC、NULLS FIRST等)。</p> <div class="language-plain line-numbers-mode"><pre class="language-plain"><code>Subtask.findAll({
  order: [
    // 将转义标题和验证DESC对一个有效的方向参数的列表
    ['title', 'DESC'],
    // 按最大(年龄)降序
    sequelize.fn('max', sequelize.col('age')),
    // 按最大(年龄)降序
    [sequelize.fn('max', sequelize.col('age')), 'DESC'],
    // 将顺序由其他函数(' col1 '， 12， 'lalala') 降序
    [sequelize.fn('otherfunction', sequelize.col('col1'), 12, 'lalala'), 'DESC'],
    // 将使用模型名称作为关联的名称来订购关联模型的createdAt。
    [Task, 'createdAt', 'DESC'],
    // 将使用模型名称作为关联的名称，通过关联模型的createdAt进行排序。
    [Task, Project, 'createdAt', 'DESC'],
    // 排序将由一个关联模型的创建使用名称的关联
    ['Task', 'createdAt', 'DESC'],
    // 使用关联的名称来创建嵌套的关联模型排序
    ['Task', 'Project', 'createdAt', 'DESC'],
    // 通过使用关联对象来创建关联模型排序. (首选方法)
    [Subtask.associations.Task, 'createdAt', 'DESC'],
    // 通过使用关联对象的嵌套关联模型的创建排序。 (首选方法)
    [Subtask.associations.Task, Task.associations.Project, 'createdAt', 'DESC'],
    // 通过使用一个简单的关联对象来创建一个关联模型。
    [{model: Task, as: 'Task'}, 'createdAt', 'DESC'],
    // 由嵌套关联模型的createdAt创建简单关联对象。
    [{model: Task, as: 'Task'}, {model: Project, as: 'Project'}, 'createdAt', 'DESC']
  ],
  // 最大年龄降序
  order: sequelize.literal('max(age) DESC'),
  // 当方向被省略时，按最大年龄升序假设升序是默认的顺序
  // 当方向被省略时，按年龄升序排列默认为升序
  order: sequelize.random()
});
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br></div></div></div></div> <!----> <div class="page-edit"><!----> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2022/01/06, 13:49:17</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/1210/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">Egg.js 技巧</div></a> <a href="/pages/110928/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">npm 使用记录</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/1210/" class="prev">Egg.js 技巧</a></span> <span class="next"><a href="/pages/110928/">npm 使用记录</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/749ce2/"><div>
            css 变量使用
            <!----></div></a> <span class="date">01-26</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/9ee936/"><div>
            js 精准和模糊获取dom
            <!----></div></a> <span class="date">01-26</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/2a8bd5/"><div>
            在 Javascript 和 Sass（或 CSS！）之间共享变量的方法
            <!----></div></a> <span class="date">01-25</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="mailto:izhaong@outlook.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/izhaong" title="GitHub" target="_blank" class="iconfont icon-github"></a><a href="https://music.163.com/#/playlist?id=755597173" title="听音乐" target="_blank" class="iconfont icon-erji"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2021-2022
    <span>izhaong | <a href="https://github.com/izhaong" target="_blank">github</a> | <a href="http://beian.miit.gov.cn/" target="_blank">蜀ICP备2021031194号</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <div class="body-bg" style="background:url() center center / cover no-repeat;opacity:0.5;"></div> <!----> <!----></div><div class="global-ui"><div></div></div></div>
    <script src="/assets/js/app.2005d9cf.js" defer></script><script src="/assets/js/2.26fadcea.js" defer></script><script src="/assets/js/31.c99d1817.js" defer></script>
  </body>
</html>
